home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume14 / flex / part02 < prev    next >
Encoding:
Internet Message Format  |  1988-05-02  |  55.9 KB

  1. Subject:  v14i080:  Flex, a lex replacement, Part02/05
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: Vern Paxson <vern@lbl-csam.arpa>
  7. Posting-number: Volume 14, Issue 80
  8. Archive-name: flex/part02
  9.  
  10. #! /bin/sh
  11. # This is a shell archive.  Remove anything before this line, then unpack
  12. # it by saving it into a file and typing "sh file".  To overwrite existing
  13. # files, type "sh file -c".  You can also feed this as standard input via
  14. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  15. # will see the following message at the end:
  16. #        "End of archive 2 (of 5)."
  17. # Contents:  dfa.c flex.fastskel main.c misc.c scan.l
  18. # Wrapped by rsalz@fig.bbn.com on Tue May  3 17:31:27 1988
  19. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  20. if test -f 'dfa.c' -a "${1}" != "-c" ; then 
  21.   echo shar: Will not clobber existing file \"'dfa.c'\"
  22. else
  23. echo shar: Extracting \"'dfa.c'\" \(10732 characters\)
  24. sed "s/^X//" >'dfa.c' <<'END_OF_FILE'
  25. X/* dfa - DFA construction routines */
  26. X
  27. X/*
  28. X * Copyright (c) 1987, the University of California
  29. X * 
  30. X * The United States Government has rights in this work pursuant to
  31. X * contract no. DE-AC03-76SF00098 between the United States Department of
  32. X * Energy and the University of California.
  33. X * 
  34. X * This program may be redistributed.  Enhancements and derivative works
  35. X * may be created provided the new works, if made available to the general
  36. X * public, are made available for use by anyone.
  37. X */
  38. X
  39. X#include "flexdef.h"
  40. X
  41. X/* epsclosure - construct the epsilon closure of a set of ndfa states
  42. X *
  43. X * synopsis
  44. X *    int t[current_max_dfa_size], numstates, accset[accnum + 1], nacc;
  45. X *    int hashval;
  46. X *    int *epsclosure();
  47. X *    t = epsclosure( t, &numstates, accset, &nacc, &hashval );
  48. X *
  49. X * NOTES
  50. X *    the epsilon closure is the set of all states reachable by an arbitrary
  51. X *  number of epsilon transitions which themselves do not have epsilon
  52. X *  transitions going out, unioned with the set of states which have non-null
  53. X *  accepting numbers.  t is an array of size numstates of nfa state numbers.
  54. X *  Upon return, t holds the epsilon closure and numstates is updated.  accset
  55. X *  holds a list of the accepting numbers, and the size of accset is given
  56. X *  by nacc.  t may be subjected to reallocation if it is not large enough
  57. X *  to hold the epsilon closure.
  58. X *
  59. X *    hashval is the hash value for the dfa corresponding to the state set
  60. X */
  61. X
  62. int *epsclosure( t, ns_addr, accset, nacc_addr, hv_addr )
  63. int *t, *ns_addr, accset[], *nacc_addr, *hv_addr;
  64. X
  65. X    {
  66. X    register int stkpos, ns, tsp;
  67. X    int numstates = *ns_addr, nacc, hashval, transsym, nfaccnum;
  68. X    int stkend, nstate;
  69. X    static int did_stk_init = false, *stk; 
  70. X
  71. X#define MARK_STATE(state) \
  72. X    trans1[state] = trans1[state] - MARKER_DIFFERENCE;
  73. X
  74. X#define IS_MARKED(state) (trans1[state] < 0)
  75. X
  76. X#define UNMARK_STATE(state) \
  77. X    trans1[state] = trans1[state] + MARKER_DIFFERENCE;
  78. X
  79. X#define CHECK_ACCEPT(state) \
  80. X    { \
  81. X    nfaccnum = accptnum[state]; \
  82. X    if ( nfaccnum != NIL ) \
  83. X        accset[++nacc] = nfaccnum; \
  84. X    }
  85. X
  86. X#define DO_REALLOCATION \
  87. X    { \
  88. X    current_max_dfa_size += MAX_DFA_SIZE_INCREMENT; \
  89. X    ++num_reallocs; \
  90. X    t = reallocate_integer_array( t, current_max_dfa_size ); \
  91. X    stk = reallocate_integer_array( stk, current_max_dfa_size ); \
  92. X    } \
  93. X
  94. X#define PUT_ON_STACK(state) \
  95. X    { \
  96. X    if ( ++stkend >= current_max_dfa_size ) \
  97. X        DO_REALLOCATION \
  98. X    stk[stkend] = state; \
  99. X    MARK_STATE(state) \
  100. X    }
  101. X
  102. X#define ADD_STATE(state) \
  103. X    { \
  104. X    if ( ++numstates >= current_max_dfa_size ) \
  105. X        DO_REALLOCATION \
  106. X    t[numstates] = state; \
  107. X    hashval = hashval + state; \
  108. X    }
  109. X
  110. X#define STACK_STATE(state) \
  111. X    { \
  112. X    PUT_ON_STACK(state) \
  113. X    CHECK_ACCEPT(state) \
  114. X    if ( nfaccnum != NIL || transchar[state] != SYM_EPSILON ) \
  115. X        ADD_STATE(state) \
  116. X    }
  117. X
  118. X    if ( ! did_stk_init )
  119. X    {
  120. X    stk = allocate_integer_array( current_max_dfa_size );
  121. X    did_stk_init = true;
  122. X    }
  123. X
  124. X    nacc = stkend = hashval = 0;
  125. X
  126. X    for ( nstate = 1; nstate <= numstates; ++nstate )
  127. X    {
  128. X    ns = t[nstate];
  129. X
  130. X    /* the state could be marked if we've already pushed it onto
  131. X     * the stack
  132. X     */
  133. X    if ( ! IS_MARKED(ns) )
  134. X        PUT_ON_STACK(ns)
  135. X
  136. X    CHECK_ACCEPT(ns)
  137. X    hashval = hashval + ns;
  138. X    }
  139. X
  140. X    for ( stkpos = 1; stkpos <= stkend; ++stkpos )
  141. X    {
  142. X    ns = stk[stkpos];
  143. X    transsym = transchar[ns];
  144. X
  145. X    if ( transsym == SYM_EPSILON )
  146. X        {
  147. X        tsp = trans1[ns] + MARKER_DIFFERENCE;
  148. X
  149. X        if ( tsp != NO_TRANSITION )
  150. X        {
  151. X        if ( ! IS_MARKED(tsp) )
  152. X            STACK_STATE(tsp)
  153. X
  154. X        tsp = trans2[ns];
  155. X
  156. X        if ( tsp != NO_TRANSITION )
  157. X            if ( ! IS_MARKED(tsp) )
  158. X            STACK_STATE(tsp)
  159. X        }
  160. X        }
  161. X    }
  162. X
  163. X    /* clear out "visit" markers */
  164. X
  165. X    for ( stkpos = 1; stkpos <= stkend; ++stkpos )
  166. X    {
  167. X    if ( IS_MARKED(stk[stkpos]) )
  168. X        {
  169. X        UNMARK_STATE(stk[stkpos])
  170. X        }
  171. X    else
  172. X        flexfatal( "consistency check failed in epsclosure()" );
  173. X    }
  174. X
  175. X    *ns_addr = numstates;
  176. X    *hv_addr = hashval;
  177. X    *nacc_addr = nacc;
  178. X
  179. X    return ( t );
  180. X    }
  181. X
  182. X
  183. X
  184. X/* increase_max_dfas - increase the maximum number of DFAs */
  185. X
  186. increase_max_dfas()
  187. X
  188. X    {
  189. X    int old_max = current_max_dfas;
  190. X
  191. X    current_max_dfas += MAX_DFAS_INCREMENT;
  192. X
  193. X    ++num_reallocs;
  194. X
  195. X    base = reallocate_integer_array( base, current_max_dfas );
  196. X    def = reallocate_integer_array( def, current_max_dfas );
  197. X    dfasiz = reallocate_integer_array( dfasiz, current_max_dfas );
  198. X    accsiz = reallocate_integer_array( accsiz, current_max_dfas );
  199. X    dhash = reallocate_integer_array( dhash, current_max_dfas );
  200. X    todo = reallocate_integer_array( todo, current_max_dfas );
  201. X    dss = reallocate_integer_pointer_array( dss, current_max_dfas );
  202. X    dfaacc = reallocate_dfaacc_union( dfaacc, current_max_dfas );
  203. X
  204. X    /* fix up todo queue */
  205. X    if ( todo_next < todo_head )
  206. X    { /* queue was wrapped around the end */
  207. X    register int i;
  208. X
  209. X    for ( i = 0; i < todo_next; ++i )
  210. X        todo[old_max + i] = todo[i];
  211. X    
  212. X    todo_next += old_max;
  213. X    }
  214. X    }
  215. X
  216. X
  217. X/* snstods - converts a set of ndfa states into a dfa state
  218. X *
  219. X * synopsis
  220. X *    int sns[numstates], numstates, newds, accset[accnum + 1], nacc, hashval;
  221. X *    int snstods();
  222. X *    is_new_state = snstods( sns, numstates, accset, nacc, hashval, &newds );
  223. X *
  224. X * on return, the dfa state number is in newds.
  225. X */
  226. X
  227. int snstods( sns, numstates, accset, nacc, hashval, newds_addr )
  228. int sns[], numstates, accset[], nacc, hashval, *newds_addr;
  229. X
  230. X    {
  231. X    int didsort = 0;
  232. X    register int i, j;
  233. X    int newds, *oldsns;
  234. X    char *malloc();
  235. X
  236. X    for ( i = 1; i <= lastdfa; ++i )
  237. X    if ( hashval == dhash[i] )
  238. X        {
  239. X        if ( numstates == dfasiz[i] )
  240. X        {
  241. X        oldsns = dss[i];
  242. X
  243. X        if ( ! didsort )
  244. X            {
  245. X            /* we sort the states in sns so we can compare it to
  246. X             * oldsns quickly.  we use bubble because there probably
  247. X             * aren't very many states
  248. X             */
  249. X            bubble( sns, numstates );
  250. X            didsort = 1;
  251. X            }
  252. X
  253. X        for ( j = 1; j <= numstates; ++j )
  254. X            if ( sns[j] != oldsns[j] )
  255. X            break;
  256. X
  257. X        if ( j > numstates )
  258. X            {
  259. X            ++dfaeql;
  260. X            *newds_addr = i;
  261. X            return ( 0 );
  262. X            }
  263. X
  264. X        ++hshcol;
  265. X        }
  266. X
  267. X        else
  268. X        ++hshsave;
  269. X        }
  270. X
  271. X    /* make a new dfa */
  272. X
  273. X    if ( ++lastdfa >= current_max_dfas )
  274. X    increase_max_dfas();
  275. X
  276. X    newds = lastdfa;
  277. X
  278. X    if ( ! (dss[newds] = (int *) malloc( (unsigned) ((numstates + 1) * sizeof( int )) )) )
  279. X    flexfatal( "dynamic memory failure in snstods()" );
  280. X
  281. X    /* if we haven't already sorted the states in sns, we do so now, so that
  282. X     * future comparisons with it can be made quickly
  283. X     */
  284. X
  285. X    if ( ! didsort )
  286. X    bubble( sns, numstates );
  287. X
  288. X    for ( i = 1; i <= numstates; ++i )
  289. X    dss[newds][i] = sns[i];
  290. X
  291. X    dfasiz[newds] = numstates;
  292. X    dhash[newds] = hashval;
  293. X
  294. X    if ( nacc == 0 )
  295. X    {
  296. X    dfaacc[newds].dfaacc_state = 0;
  297. X    accsiz[newds] = 0;
  298. X    }
  299. X
  300. X    else if ( reject )
  301. X    {
  302. X    /* we sort the accepting set in increasing order so the disambiguating
  303. X     * rule that the first rule listed is considered match in the event of
  304. X     * ties will work.  We use a bubble sort since the list is probably
  305. X     * quite small.
  306. X     */
  307. X
  308. X    bubble( accset, nacc );
  309. X
  310. X    dfaacc[newds].dfaacc_state =
  311. X        (int) malloc( (unsigned) ((nacc + 1) * sizeof( int )) );
  312. X
  313. X    if ( ! dfaacc[newds].dfaacc_state )
  314. X        flexfatal( "dynamic memory failure in snstods()" );
  315. X
  316. X    /* save the accepting set for later */
  317. X    for ( i = 1; i <= nacc; ++i )
  318. X        dfaacc[newds].dfaacc_set[i] = accset[i];
  319. X
  320. X    accsiz[newds] = nacc;
  321. X    }
  322. X
  323. X    else
  324. X    { /* find lowest numbered rule so the disambiguating rule will work */
  325. X    j = accnum + 1;
  326. X
  327. X    for ( i = 1; i <= nacc; ++i )
  328. X        if ( accset[i] < j )
  329. X        j = accset[i];
  330. X
  331. X    dfaacc[newds].dfaacc_state = j;
  332. X    }
  333. X
  334. X    *newds_addr = newds;
  335. X
  336. X    return ( 1 );
  337. X    }
  338. X
  339. X
  340. X/* symfollowset - follow the symbol transitions one step
  341. X *
  342. X * synopsis
  343. X *    int ds[current_max_dfa_size], dsize, transsym;
  344. X *    int nset[current_max_dfa_size], numstates;
  345. X *    numstates = symfollowset( ds, dsize, transsym, nset );
  346. X */
  347. X
  348. int symfollowset( ds, dsize, transsym, nset )
  349. int ds[], dsize, transsym, nset[];
  350. X
  351. X    {
  352. X    int ns, tsp, sym, i, j, lenccl, ch, numstates;
  353. X    int ccllist;
  354. X
  355. X    numstates = 0;
  356. X
  357. X    for ( i = 1; i <= dsize; ++i )
  358. X    { /* for each nfa state ns in the state set of ds */
  359. X    ns = ds[i];
  360. X    sym = transchar[ns];
  361. X    tsp = trans1[ns];
  362. X
  363. X    if ( sym < 0 )
  364. X        { /* it's a character class */
  365. X        sym = -sym;
  366. X        ccllist = cclmap[sym];
  367. X        lenccl = ccllen[sym];
  368. X
  369. X        if ( cclng[sym] )
  370. X        {
  371. X        for ( j = 0; j < lenccl; ++j )
  372. X            { /* loop through negated character class */
  373. X            ch = ccltbl[ccllist + j];
  374. X
  375. X            if ( ch > transsym )
  376. X            break;    /* transsym isn't in negated ccl */
  377. X
  378. X            else if ( ch == transsym )
  379. X            /* next 2 */ goto bottom;
  380. X            }
  381. X
  382. X        /* didn't find transsym in ccl */
  383. X        nset[++numstates] = tsp;
  384. X        }
  385. X
  386. X        else
  387. X        for ( j = 0; j < lenccl; ++j )
  388. X            {
  389. X            ch = ccltbl[ccllist + j];
  390. X
  391. X            if ( ch > transsym )
  392. X            break;
  393. X
  394. X            else if ( ch == transsym )
  395. X            {
  396. X            nset[++numstates] = tsp;
  397. X            break;
  398. X            }
  399. X            }
  400. X        }
  401. X
  402. X    else if ( sym >= 'A' && sym <= 'Z' && caseins )
  403. X        flexfatal( "consistency check failed in symfollowset" );
  404. X
  405. X    else if ( sym == SYM_EPSILON )
  406. X        { /* do nothing */
  407. X        }
  408. X
  409. X    else if ( ecgroup[sym] == transsym )
  410. X        nset[++numstates] = tsp;
  411. X
  412. bottom:
  413. X    ;
  414. X    }
  415. X
  416. X    return ( numstates );
  417. X    }
  418. X
  419. X
  420. X/* sympartition - partition characters with same out-transitions
  421. X *
  422. X * synopsis
  423. X *    integer ds[current_max_dfa_size], numstates, duplist[numecs];
  424. X *    symlist[numecs];
  425. X *    sympartition( ds, numstates, symlist, duplist );
  426. X */
  427. X
  428. sympartition( ds, numstates, symlist, duplist )
  429. int ds[], numstates, duplist[];
  430. int symlist[];
  431. X
  432. X    {
  433. X    int tch, i, j, k, ns, dupfwd[CSIZE + 1], lenccl, cclp, ich;
  434. X
  435. X    /* partitioning is done by creating equivalence classes for those
  436. X     * characters which have out-transitions from the given state.  Thus
  437. X     * we are really creating equivalence classes of equivalence classes.
  438. X     */
  439. X
  440. X    for ( i = 1; i <= numecs; ++i )
  441. X    { /* initialize equivalence class list */
  442. X    duplist[i] = i - 1;
  443. X    dupfwd[i] = i + 1;
  444. X    }
  445. X
  446. X    duplist[1] = NIL;
  447. X    dupfwd[numecs] = NIL;
  448. X
  449. X    for ( i = 1; i <= numstates; ++i )
  450. X    {
  451. X    ns = ds[i];
  452. X    tch = transchar[ns];
  453. X
  454. X    if ( tch != SYM_EPSILON )
  455. X        {
  456. X        if ( tch < -lastccl || tch > CSIZE )
  457. X        flexfatal( "bad transition character detected in sympartition()" );
  458. X
  459. X        if ( tch > 0 )
  460. X        { /* character transition */
  461. X        mkechar( ecgroup[tch], dupfwd, duplist );
  462. X        symlist[ecgroup[tch]] = 1;
  463. X        }
  464. X
  465. X        else
  466. X        { /* character class */
  467. X        tch = -tch;
  468. X
  469. X        lenccl = ccllen[tch];
  470. X        cclp = cclmap[tch];
  471. X        mkeccl( ccltbl + cclp, lenccl, dupfwd, duplist, numecs );
  472. X
  473. X        if ( cclng[tch] )
  474. X            {
  475. X            j = 0;
  476. X
  477. X            for ( k = 0; k < lenccl; ++k )
  478. X            {
  479. X            ich = ccltbl[cclp + k];
  480. X
  481. X            for ( ++j; j < ich; ++j )
  482. X                symlist[j] = 1;
  483. X            }
  484. X
  485. X            for ( ++j; j <= numecs; ++j )
  486. X            symlist[j] = 1;
  487. X            }
  488. X
  489. X        else
  490. X            for ( k = 0; k < lenccl; ++k )
  491. X            {
  492. X            ich = ccltbl[cclp + k];
  493. X            symlist[ich] = 1;
  494. X            }
  495. X        }
  496. X        }
  497. X    }
  498. X    }
  499. END_OF_FILE
  500. if test 10732 -ne `wc -c <'dfa.c'`; then
  501.     echo shar: \"'dfa.c'\" unpacked with wrong size!
  502. fi
  503. # end of 'dfa.c'
  504. fi
  505. if test -f 'flex.fastskel' -a "${1}" != "-c" ; then 
  506.   echo shar: Will not clobber existing file \"'flex.fastskel'\"
  507. else
  508. echo shar: Extracting \"'flex.fastskel'\" \(9304 characters\)
  509. sed "s/^X//" >'flex.fastskel' <<'END_OF_FILE'
  510. X/* A lexical scanner generated by flex */
  511. X
  512. X#define FLEX_FAST_SKEL
  513. X
  514. X#include "fastskeldef.h"
  515. X
  516. X%% section 1 code and the definition of YY_TRANS_OFFSET_TYPE, if needed, go here
  517. X
  518. X#ifndef FLEX_FULL_TABLE
  519. X    /* struct for yy_transition */
  520. X    struct yy_trans_info
  521. X    {
  522. X    /* v is a verify for a transition. */
  523. X    short v;
  524. X
  525. X    /* In cases where its sister v *is* a "yes, there is a transition",
  526. X         * n is* the offset (in records) to the next state.  In most cases
  527. X         * where there is no transition, the value of n is irrelevant.  If n
  528. X         * is the -1th  record of a state, though, then n is the action
  529. X     * number for that state
  530. X     */
  531. X    YY_TRANS_OFFSET_TYPE n;
  532. X    };
  533. X#endif
  534. X
  535. X%% data tables for DFA go here
  536. X
  537. X/* these declarations have to come after the section 1 code or lint gets
  538. X * confused about whether the variables are used
  539. X */
  540. XFILE *yyin = stdin, *yyout = stdout;
  541. X
  542. X/* these variables are all declared out here so that section 3 code can
  543. X * manipulate them
  544. X */
  545. static char *yy_c_buf_p;    /* points to current character in buffer */
  546. static char *yy_b_buf_p;    /* points to start of current scan */
  547. static int yy_init = 1;    /* whether we need to initialize */
  548. static int yy_start;    /* start state number */
  549. X
  550. X/* true when we've seen an EOF for the current input file */
  551. static int yy_eof_has_been_seen;
  552. X
  553. static int yy_n_chars;        /* number of characters read into yy_ch_buf */
  554. X
  555. X/* yy_ch_buf has to be 2 characters longer than YY_BUF_SIZE because we need
  556. X * to put in 2 end-of-buffer characters (this is explained where it is
  557. X * done) at the end of yy_ch_buf
  558. X */
  559. static char yy_ch_buf[YY_BUF_SIZE + 2];
  560. X
  561. X/* yy_hold_char holds the character lost when yytext is formed */
  562. static char yy_hold_char;
  563. char *yytext;
  564. static int yyleng;    /* length of yytext */
  565. X
  566. static YY_CS_TYPE yy_last_accepting_state;
  567. static char *yy_last_accepting_cpos;
  568. X
  569. static YY_CS_TYPE yy_get_previous_state();
  570. static int yy_get_next_buffer();
  571. X
  572. X#define FLEX_USES_BACKTRACKING
  573. X
  574. X#ifdef FLEX_USES_BACKTRACKING
  575. X#    ifdef FLEX_FULL_TABLE
  576. X#    define YY_BACKTRACKING_ACTION \
  577. X        if ( l[yy_current_state] ) \
  578. X            { \
  579. X            yy_last_accepting_state = yy_current_state; \
  580. X            yy_last_accepting_cpos = yy_c_buf_p; \
  581. X            }
  582. X#    else
  583. X#    define YY_BACKTRACKING_ACTION \
  584. X        if ( yy_current_state[-1].n ) \
  585. X            { \
  586. X            yy_last_accepting_state = yy_current_state; \
  587. X            yy_last_accepting_cpos = yy_c_buf_p; \
  588. X            }
  589. X#    endif
  590. X#else
  591. X#    define YY_BACKTRACKING_ACTION
  592. X#endif
  593. X
  594. YY_DECL
  595. X    {
  596. X    register YY_CS_TYPE yy_current_state;
  597. X    register int yy_c;
  598. X    register struct yy_trans_info *yy_trans_info;
  599. X    register int yy_act;
  600. X
  601. X%% user's declarations go here
  602. X
  603. X    if ( yy_init )
  604. X    {
  605. X    yy_start = 1;    /* first start state */
  606. X
  607. new_file:
  608. X    /* this is where we enter upon encountering and end-of-file and
  609. X     * yywrap() indicating that we should continue processing
  610. X     */
  611. X
  612. X    /* we put in the '\n' and start reading from [1] so that an
  613. X     * initial match-at-newline will be true.
  614. X     */
  615. X
  616. X    yy_ch_buf[0] = '\n';
  617. X    yy_n_chars = 1;
  618. X
  619. X    /* we always need two end-of-buffer characters.  The first causes
  620. X     * a transition to the end-of-buffer state.  The second causes
  621. X     * a jam in that state.
  622. X     */
  623. X    yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;
  624. X    yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
  625. X
  626. X    yy_eof_has_been_seen = 0;
  627. X
  628. X    YY_FAST_INIT;
  629. X    yy_init = 0;
  630. X    }
  631. X
  632. X    while ( 1 )        /* loops until end-of-file is reached */
  633. X    {
  634. X    /* support of yytext and yyleng */
  635. X    YY_DO_BEFORE_SCAN;
  636. X
  637. X    /* yy_b_buf_p points to the position in yy_ch_buf of the start of the
  638. X     * current run.
  639. X     */
  640. X    yy_b_buf_p = yy_c_buf_p;
  641. X
  642. X        YY_FIND_START_STATE( yy_current_state );
  643. X
  644. X        YY_FIND_NEXT_MATCH;
  645. X
  646. X    YY_DO_BEFORE_ACTION;
  647. X
  648. X/* we need this label to process the very last action (right before the end of
  649. X * the file)
  650. X */
  651. do_action:
  652. X    YY_FIND_ACTION( yy_act );
  653. X
  654. X#ifdef FLEX_DEBUG
  655. X    fprintf( stderr, "--accepting rule #%d\n", yy_act );
  656. X#endif
  657. X    switch ( yy_act )
  658. X        {
  659. X%% actions go here
  660. X
  661. X        case YY_BACK_TRACK:
  662. X        YY_DO_BEFORE_SCAN; /* undo the effects of YY_DO_BEFORE_ACTION */
  663. X        yy_c_buf_p = yy_last_accepting_cpos + 1;
  664. X        yy_current_state = yy_last_accepting_state;
  665. X        YY_DO_BEFORE_ACTION;
  666. X        goto do_action;
  667. X
  668. X        case YY_NEW_FILE:
  669. X        break; /* begin reading from new file */
  670. X
  671. X        case YY_DO_DEFAULT:
  672. X        /* we have to eat up one character and recompute yytext and
  673. X         * yyleng
  674. X         */
  675. X        YY_DO_BEFORE_SCAN; /* undo the effects of YY_DO_BEFORE_ACTION */
  676. X        ++yy_c_buf_p;
  677. X        YY_DO_BEFORE_ACTION;
  678. X        YY_DEFAULT_ACTION;
  679. X        break;
  680. X
  681. X        case YY_END_OF_BUFFER:
  682. X        YY_DO_BEFORE_SCAN; /* undo the effects of YY_DO_BEFORE_ACTION */
  683. X
  684. X        switch ( yy_get_next_buffer() )
  685. X            {
  686. X            case EOB_ACT_END_OF_FILE:
  687. X            {
  688. X            if ( yywrap() )
  689. X                {
  690. X                /* note: because we've taken care in
  691. X                 * yy_get_next_buffer() to have set up yy_b_buf_p,
  692. X                 * we can now set up yy_c_buf_p so that if some
  693. X                 * total hoser (like flex itself) wants
  694. X                 * to call the scanner after we return the
  695. X                 * YY_NULL, it'll still work - another YY_NULL
  696. X                  * will get returned.
  697. X                 */
  698. X                yy_c_buf_p = yy_b_buf_p;
  699. X                return ( YY_NULL );
  700. X                }
  701. X
  702. X            else
  703. X                goto new_file;
  704. X            }
  705. X            break;
  706. X
  707. X            case EOB_ACT_RESTART_SCAN:
  708. X            yy_c_buf_p = yy_b_buf_p;
  709. X
  710. X            YY_DO_BEFORE_RESTART;
  711. X            break;
  712. X
  713. X            case EOB_ACT_LAST_MATCH:
  714. X            yy_c_buf_p = &yy_ch_buf[yy_n_chars];
  715. X
  716. X            yy_current_state = yy_get_previous_state();
  717. X
  718. X            YY_DO_BEFORE_ACTION;
  719. X
  720. X            goto do_action;
  721. X            }
  722. X        break;
  723. X
  724. X        default:
  725. X        printf( "action # %d\n", yy_act );
  726. X        YY_FATAL_ERROR( "fatal flex scanner internal error" );
  727. X        }
  728. X    }
  729. X    }
  730. X
  731. X
  732. X/* yy_get_next_buffer - try to read in new buffer
  733. X *
  734. X * synopsis
  735. X *     int yy_get_next_buffer();
  736. X *     
  737. X * returns a code representing an action
  738. X *     EOB_ACT_LAST_MATCH - 
  739. X *     EOB_ACT_RESTART_SCAN - restart the scanner
  740. X *     EOB_ACT_END_OF_FILE - end of file
  741. X */
  742. X
  743. static int yy_get_next_buffer()
  744. X
  745. X    {
  746. X    if ( yy_c_buf_p != &yy_ch_buf[yy_n_chars + 1] )
  747. X    {
  748. X    YY_FATAL_ERROR( "NULL in input" );
  749. X    /*NOTREACHED*/
  750. X    }
  751. X
  752. X    else
  753. X    { /* try to read more data */
  754. X    register char *dest = yy_ch_buf;
  755. X    register char *source = yy_b_buf_p - 1; /* copy prev. char, too */
  756. X    register int number_to_move, i;
  757. X    int ret_val;
  758. X    
  759. X    /* first move last chars to start of buffer */
  760. X    number_to_move = yy_c_buf_p - yy_b_buf_p;
  761. X
  762. X    for ( i = 0; i < number_to_move; ++i )
  763. X        *(dest++) = *(source++);
  764. X
  765. X    if ( yy_eof_has_been_seen )
  766. X        /* don't do the read, it's not guaranteed to return an EOF,
  767. X         * just force an EOF
  768. X         */
  769. X        yy_n_chars = 0;
  770. X
  771. X    else
  772. X        /* read in more data */
  773. X        YY_INPUT( (&yy_ch_buf[number_to_move]), yy_n_chars,
  774. X              YY_BUF_SIZE - number_to_move - 1 );
  775. X
  776. X    if ( yy_n_chars == 0 )
  777. X        {
  778. X        if ( number_to_move == 1 )
  779. X        ret_val = EOB_ACT_END_OF_FILE;
  780. X        else
  781. X        ret_val = EOB_ACT_LAST_MATCH;
  782. X
  783. X        yy_eof_has_been_seen = 1;
  784. X        }
  785. X
  786. X    else
  787. X        ret_val = EOB_ACT_RESTART_SCAN;
  788. X
  789. X    yy_n_chars += number_to_move;
  790. X    yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;
  791. X    yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
  792. X
  793. X    /* yy_b_buf_p begins at the second character in
  794. X     * yy_ch_buf; the first character is the one which
  795. X     * preceded it before reading in the latest buffer;
  796. X     * it needs to be kept around in case it's a
  797. X     * newline, so yy_get_previous_state() will have
  798. X     * with '^' rules active
  799. X     */
  800. X
  801. X    yy_b_buf_p = &yy_ch_buf[1];
  802. X
  803. X    return ( ret_val );
  804. X    }
  805. X    }
  806. X
  807. X
  808. X/* yy_get_previous_state - get the state just before the eob char was reached
  809. X *
  810. X * synopsis
  811. X *     YY_CS_TYPE yy_get_previous_state();
  812. X */
  813. X
  814. static YY_CS_TYPE yy_get_previous_state()
  815. X
  816. X    {
  817. X    register YY_CS_TYPE yy_cur_state;
  818. X    register char *yy_temp_char_ptr;
  819. X
  820. X    YY_FIND_START_STATE( yy_cur_state );
  821. X
  822. X    for ( yy_temp_char_ptr = yy_b_buf_p; yy_temp_char_ptr < yy_c_buf_p; )
  823. X    YY_GET_NEXT_STATE;
  824. X
  825. X    return ( yy_cur_state );
  826. X    }
  827. X
  828. X
  829. static unput( c )
  830. int c;
  831. X
  832. X    {
  833. X    YY_DO_BEFORE_SCAN; /* undo effects of setting up yytext */
  834. X
  835. X    if ( yy_c_buf_p < yy_ch_buf + 2 )
  836. X    { /* need to shift things up to make room */
  837. X    register int number_to_move = yy_n_chars + 2; /* +2 for EOB chars */
  838. X    register char *dest = &yy_ch_buf[YY_BUF_SIZE + 2];
  839. X    register char *source = &yy_ch_buf[number_to_move];
  840. X
  841. X    while ( source > yy_ch_buf )
  842. X        *--dest = *--source;
  843. X
  844. X    yy_c_buf_p += dest - source;
  845. X    yy_b_buf_p += dest - source;
  846. X
  847. X    if ( yy_c_buf_p < yy_ch_buf + 2 )
  848. X        YY_FATAL_ERROR( "flex scanner push-back overflow" );
  849. X    }
  850. X
  851. X    if ( yy_c_buf_p > yy_b_buf_p && yy_c_buf_p[-1] == '\n' )
  852. X    yy_c_buf_p[-2] = '\n';
  853. X
  854. X    *--yy_c_buf_p = c;
  855. X
  856. X    YY_DO_BEFORE_ACTION; /* set up yytext again */
  857. X    }
  858. X
  859. X
  860. static int input()
  861. X
  862. X    {
  863. X    int c;
  864. X
  865. X    YY_DO_BEFORE_SCAN;
  866. X
  867. X    if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
  868. X    { /* need more input */
  869. X    yy_b_buf_p = yy_c_buf_p;
  870. X    ++yy_c_buf_p;
  871. X
  872. X    switch ( yy_get_next_buffer() )
  873. X        {
  874. X        /* this code, unfortunately, is somewhat redundant with
  875. X         * that above
  876. X         */
  877. X        case EOB_ACT_END_OF_FILE:
  878. X        {
  879. X        if ( yywrap() )
  880. X            {
  881. X            yy_c_buf_p = yy_b_buf_p;
  882. X            return ( EOF );
  883. X            }
  884. X
  885. X        yy_ch_buf[0] = '\n';
  886. X        yy_n_chars = 1;
  887. X        yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;
  888. X        yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
  889. X        yy_eof_has_been_seen = 0;
  890. X
  891. X        YY_FAST_INIT;
  892. X
  893. X        return ( input() );
  894. X        }
  895. X        break;
  896. X
  897. X        case EOB_ACT_RESTART_SCAN:
  898. X        yy_c_buf_p = yy_b_buf_p;
  899. X        break;
  900. X
  901. X        case EOB_ACT_LAST_MATCH:
  902. X        YY_FATAL_ERROR( "unexpected last match in input()" );
  903. X        }
  904. X    }
  905. X
  906. X    c = *yy_c_buf_p++;
  907. X
  908. X    YY_DO_BEFORE_RESTART;
  909. X
  910. X    return ( c );
  911. X    }
  912. END_OF_FILE
  913. if test 9304 -ne `wc -c <'flex.fastskel'`; then
  914.     echo shar: \"'flex.fastskel'\" unpacked with wrong size!
  915. fi
  916. # end of 'flex.fastskel'
  917. fi
  918. if test -f 'main.c' -a "${1}" != "-c" ; then 
  919.   echo shar: Will not clobber existing file \"'main.c'\"
  920. else
  921. echo shar: Extracting \"'main.c'\" \(12885 characters\)
  922. sed "s/^X//" >'main.c' <<'END_OF_FILE'
  923. X/* flex - tool to generate fast lexical analyzers
  924. X *
  925. X *
  926. X * Copyright (c) 1987, the University of California
  927. X * 
  928. X * The United States Government has rights in this work pursuant to
  929. X * contract no. DE-AC03-76SF00098 between the United States Department of
  930. X * Energy and the University of California.
  931. X * 
  932. X * This program may be redistributed.  Enhancements and derivative works
  933. X * may be created provided the new works, if made available to the general
  934. X * public, are made available for use by anyone.
  935. X *
  936. X *
  937. X * ver   date  who    remarks
  938. X * ---   ----  ------ -------------------------------------------------------
  939. X * 04b 30sep87 kg, vp .implemented (part of) Van Jacobson's fast scanner design
  940. X * 04a 27jun86 vp     .translated from Ratfor into C
  941. X * 01a 22aug83 vp     .written.  Original version by Jef Poskanzer.
  942. X */
  943. X
  944. X#include "flexdef.h"
  945. X
  946. X
  947. X/* these globals are all defined and commented in flexdef.h */
  948. int printstats, syntaxerror, eofseen, ddebug, trace, spprdflt;
  949. int interactive, caseins, useecs, fulltbl, usemecs, reject;
  950. int fullspd, gen_line_dirs;
  951. int datapos, dataline, linenum;
  952. XFILE *skelfile = NULL;
  953. char *infilename = NULL;
  954. int onestate[ONE_STACK_SIZE], onesym[ONE_STACK_SIZE];
  955. int onenext[ONE_STACK_SIZE], onedef[ONE_STACK_SIZE], onesp;
  956. int current_mns;
  957. int accnum, *firstst, *lastst, *finalst, *transchar;
  958. int *trans1, *trans2, *accptnum, lastnfa;
  959. int numtemps, numprots, protprev[MSP], protnext[MSP], prottbl[MSP];
  960. int protcomst[MSP], firstprot, lastprot, protsave[PROT_SAVE_SIZE];
  961. int numecs, nextecm[CSIZE + 1], ecgroup[CSIZE + 1], nummecs, tecfwd[CSIZE + 1];
  962. int tecbck[CSIZE + 1];
  963. int lastsc, current_max_scs, *scset, *scbol, *scxclu, *actvsc;
  964. int current_max_dfa_size, current_max_xpairs;
  965. int current_max_template_xpairs, current_max_dfas;
  966. int lastdfa, *nxt, *chk, *tnxt;
  967. int *base, *def, tblend, firstfree, numtemps, **dss, *dfasiz;
  968. union dfaacc_union *dfaacc;
  969. int *accsiz, *dhash, *todo, todo_head, todo_next, numas;
  970. int numsnpairs, jambase, jamstate;
  971. int lastccl, current_maxccls, *cclmap, *ccllen, *cclng, cclreuse;
  972. int current_max_ccl_tbl_size;
  973. char *ccltbl;
  974. char *starttime, *endtime, nmstr[MAXLINE];
  975. int sectnum, nummt, hshcol, dfaeql, numeps, eps2, num_reallocs;
  976. int tmpuses, totnst, peakpairs, numuniq, numdup, hshsave;
  977. XFILE *temp_action_file;
  978. int end_of_buffer_state;
  979. char *action_file_name = "/tmp/flexXXXXXX";
  980. X
  981. X
  982. X/* flex - main program
  983. X *
  984. X * synopsis (from the shell)
  985. X *    flex [-v] [file ...]
  986. X */
  987. X
  988. main( argc, argv )
  989. int argc;
  990. char **argv;
  991. X
  992. X    {
  993. X    flexinit( argc, argv );
  994. X
  995. X    readin();
  996. X
  997. X    if ( ! syntaxerror )
  998. X    {
  999. X    /* convert the ndfa to a dfa */
  1000. X    ntod();
  1001. X
  1002. X    /* generate the C state transition tables from the DFA */
  1003. X    make_tables();
  1004. X    }
  1005. X
  1006. X    /* note, flexend does not return.  It exits with its argument as status. */
  1007. X
  1008. X    flexend( 0 );
  1009. X    }
  1010. X
  1011. X
  1012. X/* flexend - terminate flex
  1013. X *
  1014. X * synopsis
  1015. X *    int status;
  1016. X *    flexend( status );
  1017. X *
  1018. X *    status is exit status.
  1019. X *
  1020. X * note
  1021. X *    This routine does not return.
  1022. X */
  1023. X
  1024. flexend( status )
  1025. int status;
  1026. X
  1027. X    {
  1028. X    int tblsiz;
  1029. X    char *gettime();
  1030. X
  1031. X    if ( skelfile != NULL )
  1032. X    (void) fclose( skelfile );
  1033. X
  1034. X    if ( temp_action_file )
  1035. X    {
  1036. X    (void) fclose( temp_action_file );
  1037. X    (void) unlink( action_file_name );
  1038. X    }
  1039. X
  1040. X    if ( printstats )
  1041. X    {
  1042. X    endtime = gettime();
  1043. X
  1044. X    fprintf( stderr, "flex usage statistics:\n" );
  1045. X    fprintf( stderr, "  started at %s, finished at %s\n",
  1046. X         starttime, endtime );
  1047. X
  1048. X    fprintf( stderr, "  %d/%d NFA states\n", lastnfa, current_mns );
  1049. X    fprintf( stderr, "  %d/%d DFA states (%d words)\n", lastdfa,
  1050. X             current_max_dfas, totnst );
  1051. X    fprintf( stderr, "  %d rules\n", accnum );
  1052. X    fprintf( stderr, "  %d/%d start conditions\n", lastsc,
  1053. X             current_max_scs );
  1054. X    fprintf( stderr, "  %d epsilon states, %d double epsilon states\n",
  1055. X         numeps, eps2 );
  1056. X
  1057. X    if ( lastccl == 0 )
  1058. X        fprintf( stderr, "  no character classes\n" );
  1059. X    else
  1060. X        fprintf( stderr,
  1061. X    "  %d/%d character classes needed %d/%d words of storage, %d reused\n",
  1062. X             lastccl, current_maxccls,
  1063. X             cclmap[lastccl] + ccllen[lastccl] - 1,
  1064. X             current_max_ccl_tbl_size, cclreuse );
  1065. X
  1066. X    fprintf( stderr, "  %d state/nextstate pairs created\n", numsnpairs );
  1067. X    fprintf( stderr, "  %d/%d unique/duplicate transitions\n",
  1068. X         numuniq, numdup );
  1069. X
  1070. X    if ( fulltbl )
  1071. X        {
  1072. X        tblsiz = lastdfa * numecs;
  1073. X        fprintf( stderr, "  %d table entries\n", tblsiz );
  1074. X        }
  1075. X
  1076. X    else
  1077. X        {
  1078. X        tblsiz = 2 * (lastdfa + numtemps) + 2 * tblend;
  1079. X
  1080. X        fprintf( stderr, "  %d/%d base/def entries created\n",
  1081. X             lastdfa + numtemps, current_max_dfas );
  1082. X        fprintf( stderr, "  %d/%d (peak %d) nxt/chk entries created\n",
  1083. X             tblend, current_max_xpairs, peakpairs );
  1084. X        fprintf( stderr,
  1085. X             "  %d/%d (peak %d) template nxt/chk entries created\n",
  1086. X             numtemps * nummecs, current_max_template_xpairs,
  1087. X             numtemps * numecs );
  1088. X        fprintf( stderr, "  %d empty table entries\n", nummt );
  1089. X        fprintf( stderr, "  %d protos created\n", numprots );
  1090. X        fprintf( stderr, "  %d templates created, %d uses\n",
  1091. X             numtemps, tmpuses );
  1092. X        }
  1093. X
  1094. X    if ( useecs )
  1095. X        {
  1096. X        tblsiz = tblsiz + CSIZE;
  1097. X        fprintf( stderr, "  %d/%d equivalence classes created\n",
  1098. X             numecs, CSIZE );
  1099. X        }
  1100. X
  1101. X    if ( usemecs )
  1102. X        {
  1103. X        tblsiz = tblsiz + numecs;
  1104. X        fprintf( stderr, "  %d/%d meta-equivalence classes created\n",
  1105. X             nummecs, CSIZE );
  1106. X        }
  1107. X
  1108. X    fprintf( stderr, "  %d (%d saved) hash collisions, %d DFAs equal\n",
  1109. X         hshcol, hshsave, dfaeql );
  1110. X    fprintf( stderr, "  %d sets of reallocations needed\n", num_reallocs );
  1111. X    fprintf( stderr, "  %d total table entries needed\n", tblsiz );
  1112. X    }
  1113. X
  1114. X    exit( status );
  1115. X    }
  1116. X
  1117. X
  1118. X/* flexinit - initialize flex
  1119. X *
  1120. X * synopsis
  1121. X *    int argc;
  1122. X *    char **argv;
  1123. X *    flexinit( argc, argv );
  1124. X */
  1125. X
  1126. flexinit( argc, argv )
  1127. int argc;
  1128. char **argv;
  1129. X
  1130. X    {
  1131. X    int i, sawcmpflag, use_stdout;
  1132. X    char *arg, *skelname = NULL, *gettime(), clower(), *mktemp();
  1133. X
  1134. X    printstats = syntaxerror = trace = spprdflt = interactive = caseins = false;
  1135. X    ddebug = fulltbl = reject = fullspd = false;
  1136. X    gen_line_dirs = usemecs = useecs = true;
  1137. X
  1138. X    sawcmpflag = false;
  1139. X    use_stdout = false;
  1140. X
  1141. X    /* read flags */
  1142. X    for ( --argc, ++argv; argc ; --argc, ++argv )
  1143. X    {
  1144. X    if ( argv[0][0] != '-' || argv[0][1] == '\0' )
  1145. X        break;
  1146. X
  1147. X    arg = argv[0];
  1148. X
  1149. X    for ( i = 1; arg[i] != '\0'; ++i )
  1150. X        switch ( arg[i] )
  1151. X        {
  1152. X        case 'c':
  1153. X            if ( i != 1 )
  1154. X            flexerror( "-c flag must be given separately" );
  1155. X
  1156. X            if ( ! sawcmpflag )
  1157. X            {
  1158. X            useecs = false;
  1159. X            usemecs = false;
  1160. X            fulltbl = false;
  1161. X            sawcmpflag = true;
  1162. X            }
  1163. X
  1164. X            for ( ++i; arg[i] != '\0'; ++i )
  1165. X            switch ( clower( arg[i] ) )
  1166. X                {
  1167. X                case 'e':
  1168. X                useecs = true;
  1169. X                break;
  1170. X
  1171. X                case 'F':
  1172. X                fullspd = true;
  1173. X                break;
  1174. X
  1175. X                case 'f':
  1176. X                fulltbl = true;
  1177. X                break;
  1178. X
  1179. X                case 'm':
  1180. X                usemecs = true;
  1181. X                break;
  1182. X
  1183. X                default:
  1184. X                lerrif( "unknown -c option %c",
  1185. X                    (int) arg[i] );
  1186. X                break;
  1187. X                }
  1188. X            
  1189. X            goto get_next_arg;
  1190. X
  1191. X        case 'd':
  1192. X            ddebug = true;
  1193. X            break;
  1194. X
  1195. X        case 'f':
  1196. X            useecs = usemecs = false;
  1197. X            fulltbl = true;
  1198. X            break;
  1199. X
  1200. X        case 'I':
  1201. X            interactive = true;
  1202. X            break;
  1203. X
  1204. X        case 'i':
  1205. X            caseins = true;
  1206. X            break;
  1207. X
  1208. X        case 'L':
  1209. X            gen_line_dirs = false;
  1210. X            break;
  1211. X
  1212. X        case 'r':
  1213. X            reject = true;
  1214. X            break;
  1215. X
  1216. X        case 'F':
  1217. X            useecs = usemecs = false;
  1218. X            fullspd = true;
  1219. X            break;
  1220. X
  1221. X        case 'S':
  1222. X            if ( i != 1 )
  1223. X            flexerror( "-S flag must be given separately" );
  1224. X
  1225. X            skelname = arg + i + 1;
  1226. X            goto get_next_arg;
  1227. X
  1228. X        case 's':
  1229. X            spprdflt = true;
  1230. X            break;
  1231. X
  1232. X        case 't':
  1233. X            use_stdout = true;
  1234. X            break;
  1235. X
  1236. X        case 'T':
  1237. X            trace = true;
  1238. X            break;
  1239. X
  1240. X        case 'v':
  1241. X            printstats = true;
  1242. X            break;
  1243. X
  1244. X        default:
  1245. X            lerrif( "unknown flag %c", (int) arg[i] );
  1246. X            break;
  1247. X        }
  1248. X
  1249. get_next_arg: /* used by -c and -S flags in lieu of a "continue 2" control */
  1250. X    ;
  1251. X    }
  1252. X
  1253. X    if ( (fulltbl || fullspd) && usemecs )
  1254. X    flexerror( "full table and -cm don't make sense together" );
  1255. X
  1256. X    if ( (fulltbl || fullspd) && interactive )
  1257. X    flexerror( "full table and -I are (currently) incompatible" );
  1258. X
  1259. X    if ( (fulltbl || fullspd) && reject )
  1260. X    flexerror( "reject (-r) cannot be used with -f or -F" );
  1261. X
  1262. X    if ( fulltbl && fullspd )
  1263. X    flexerror( "full table and -F are mutually exclusive" );
  1264. X
  1265. X    if ( ! skelname )
  1266. X    {
  1267. X    static char skeleton_name_storage[400];
  1268. X
  1269. X    skelname = skeleton_name_storage;
  1270. X
  1271. X    if ( fullspd || fulltbl )
  1272. X        (void) strcpy( skelname, FAST_SKELETON_FILE );
  1273. X    else
  1274. X        (void) strcpy( skelname, DEFAULT_SKELETON_FILE );
  1275. X    }
  1276. X
  1277. X    if ( ! use_stdout )
  1278. X    {
  1279. X    FILE *prev_stdout = freopen( "lex.yy.c", "w", stdout );
  1280. X
  1281. X    if ( prev_stdout == NULL )
  1282. X        flexerror( "could not create lex.yy.c" );
  1283. X    }
  1284. X
  1285. X    if ( argc )
  1286. X    {
  1287. X    if ( argc > 1 )
  1288. X        flexerror( "extraneous argument(s) given" );
  1289. X
  1290. X    yyin = fopen( infilename = argv[0], "r" );
  1291. X
  1292. X    if ( yyin == NULL )
  1293. X        lerrsf( "can't open %s", argv[0] );
  1294. X    }
  1295. X
  1296. X    else
  1297. X    yyin = stdin;
  1298. X
  1299. X    lastccl = 0;
  1300. X    lastsc = 0;
  1301. X
  1302. X    /* initialize the statistics */
  1303. X    starttime = gettime();
  1304. X
  1305. X    if ( (skelfile = fopen( skelname, "r" )) == NULL )
  1306. X    lerrsf( "can't open skeleton file %s", skelname );
  1307. X
  1308. X    (void) mktemp( action_file_name );
  1309. X
  1310. X    if ( (temp_action_file = fopen( action_file_name, "w" )) == NULL )
  1311. X    lerrsf( "can't open temporary action file %s", action_file_name );
  1312. X
  1313. X    lastdfa = lastnfa = accnum = numas = numsnpairs = tmpuses = 0;
  1314. X    numecs = numeps = eps2 = num_reallocs = hshcol = dfaeql = totnst = 0;
  1315. X    numuniq = numdup = hshsave = eofseen = datapos = dataline = 0;
  1316. X    onesp = numprots = 0;
  1317. X
  1318. X    linenum = sectnum = 1;
  1319. X    firstprot = NIL;
  1320. X
  1321. X    /* used in mkprot() so that the first proto goes in slot 1
  1322. X     * of the proto queue
  1323. X     */
  1324. X    lastprot = 1;
  1325. X
  1326. X    if ( useecs )
  1327. X    {
  1328. X    /* set up doubly-linked equivalence classes */
  1329. X    ecgroup[1] = NIL;
  1330. X
  1331. X    for ( i = 2; i <= CSIZE; ++i )
  1332. X        {
  1333. X        ecgroup[i] = i - 1;
  1334. X        nextecm[i - 1] = i;
  1335. X        }
  1336. X
  1337. X    nextecm[CSIZE] = NIL;
  1338. X    }
  1339. X
  1340. X    else
  1341. X    { /* put everything in its own equivalence class */
  1342. X    for ( i = 1; i <= CSIZE; ++i )
  1343. X        {
  1344. X        ecgroup[i] = i;
  1345. X        nextecm[i] = BAD_SUBSCRIPT;    /* to catch errors */
  1346. X        }
  1347. X    }
  1348. X
  1349. X    set_up_initial_allocations();
  1350. X    }
  1351. X
  1352. X
  1353. X/* readin - read in the rules section of the input file(s)
  1354. X *
  1355. X * synopsis
  1356. X *    readin();
  1357. X */
  1358. X
  1359. readin()
  1360. X
  1361. X    {
  1362. X    fputs( "#define YY_DEFAULT_ACTION ", stdout );
  1363. X
  1364. X    if ( spprdflt )
  1365. X    fputs( "YY_FATAL_ERROR( \"flex scanner jammed\" )", stdout );
  1366. X    else
  1367. X    fputs( "ECHO", stdout );
  1368. X
  1369. X    fputs( ";\n", stdout );
  1370. X
  1371. X    if ( ddebug )
  1372. X    puts( "#define FLEX_DEBUG" );
  1373. X    if ( useecs )
  1374. X    puts( "#define FLEX_USE_ECS" );
  1375. X    if ( usemecs )
  1376. X    puts( "#define FLEX_USE_MECS" );
  1377. X    if ( interactive )
  1378. X    puts( "#define FLEX_INTERACTIVE_SCANNER" );
  1379. X    if ( reject )
  1380. X    puts( "#define FLEX_REJECT_ENABLED" );
  1381. X    if ( fulltbl )
  1382. X    puts( "#define FLEX_FULL_TABLE" );
  1383. X
  1384. X    skelout();
  1385. X
  1386. X    line_directive_out( stdout );
  1387. X
  1388. X    if ( yyparse() )
  1389. X    lerrif( "fatal parse error at line %d", linenum );
  1390. X
  1391. X    if ( useecs )
  1392. X    {
  1393. X    numecs = cre8ecs( nextecm, ecgroup, CSIZE );
  1394. X    ccl2ecl();
  1395. X    }
  1396. X
  1397. X    else
  1398. X    numecs = CSIZE;
  1399. X
  1400. X    }
  1401. X
  1402. X
  1403. X
  1404. X/* set_up_initial_allocations - allocate memory for internal tables */
  1405. X
  1406. set_up_initial_allocations()
  1407. X
  1408. X    {
  1409. X    current_mns = INITIAL_MNS;
  1410. X    firstst = allocate_integer_array( current_mns );
  1411. X    lastst = allocate_integer_array( current_mns );
  1412. X    finalst = allocate_integer_array( current_mns );
  1413. X    transchar = allocate_integer_array( current_mns );
  1414. X    trans1 = allocate_integer_array( current_mns );
  1415. X    trans2 = allocate_integer_array( current_mns );
  1416. X    accptnum = allocate_integer_array( current_mns );
  1417. X
  1418. X    current_max_scs = INITIAL_MAX_SCS;
  1419. X    scset = allocate_integer_array( current_max_scs );
  1420. X    scbol = allocate_integer_array( current_max_scs );
  1421. X    scxclu = allocate_integer_array( current_max_scs );
  1422. X    actvsc = allocate_integer_array( current_max_scs );
  1423. X
  1424. X    current_maxccls = INITIAL_MAXCCLS;
  1425. X    cclmap = allocate_integer_array( current_maxccls );
  1426. X    ccllen = allocate_integer_array( current_maxccls );
  1427. X    cclng = allocate_integer_array( current_maxccls );
  1428. X
  1429. X    current_max_ccl_tbl_size = INITIAL_MAX_CCL_TBL_SIZE;
  1430. X    ccltbl = allocate_character_array( current_max_ccl_tbl_size );
  1431. X
  1432. X    current_max_dfa_size = INITIAL_MAX_DFA_SIZE;
  1433. X
  1434. X    current_max_xpairs = INITIAL_MAX_XPAIRS;
  1435. X    nxt = allocate_integer_array( current_max_xpairs );
  1436. X    chk = allocate_integer_array( current_max_xpairs );
  1437. X
  1438. X    current_max_template_xpairs = INITIAL_MAX_TEMPLATE_XPAIRS;
  1439. X    tnxt = allocate_integer_array( current_max_template_xpairs );
  1440. X
  1441. X    current_max_dfas = INITIAL_MAX_DFAS;
  1442. X    base = allocate_integer_array( current_max_dfas );
  1443. X    def = allocate_integer_array( current_max_dfas );
  1444. X    dfasiz = allocate_integer_array( current_max_dfas );
  1445. X    accsiz = allocate_integer_array( current_max_dfas );
  1446. X    dhash = allocate_integer_array( current_max_dfas );
  1447. X    todo = allocate_integer_array( current_max_dfas );
  1448. X    dss = allocate_integer_pointer_array( current_max_dfas );
  1449. X    dfaacc = allocate_dfaacc_union( current_max_dfas );
  1450. X    }
  1451. END_OF_FILE
  1452. if test 12885 -ne `wc -c <'main.c'`; then
  1453.     echo shar: \"'main.c'\" unpacked with wrong size!
  1454. fi
  1455. # end of 'main.c'
  1456. fi
  1457. if test -f 'misc.c' -a "${1}" != "-c" ; then 
  1458.   echo shar: Will not clobber existing file \"'misc.c'\"
  1459. else
  1460. echo shar: Extracting \"'misc.c'\" \(9991 characters\)
  1461. sed "s/^X//" >'misc.c' <<'END_OF_FILE'
  1462. X/* misc - miscellaneous flex routines */
  1463. X
  1464. X/*
  1465. X * Copyright (c) 1987, the University of California
  1466. X * 
  1467. X * The United States Government has rights in this work pursuant to
  1468. X * contract no. DE-AC03-76SF00098 between the United States Department of
  1469. X * Energy and the University of California.
  1470. X * 
  1471. X * This program may be redistributed.  Enhancements and derivative works
  1472. X * may be created provided the new works, if made available to the general
  1473. X * public, are made available for use by anyone.
  1474. X */
  1475. X
  1476. X#include <ctype.h>
  1477. X#include "flexdef.h"
  1478. X
  1479. char *malloc(), *realloc();
  1480. X
  1481. X
  1482. X/* action_out - write the actions from the temporary file to lex.yy.c
  1483. X *
  1484. X * synopsis
  1485. X *     action_out();
  1486. X *
  1487. X *     Copies the action file up to %% (or end-of-file) to lex.yy.c
  1488. X */
  1489. X
  1490. action_out()
  1491. X
  1492. X    {
  1493. X    char buf[MAXLINE];
  1494. X
  1495. X    while ( fgets( buf, MAXLINE, temp_action_file ) != NULL )
  1496. X    if ( buf[0] == '%' && buf[1] == '%' )
  1497. X        break;
  1498. X    else
  1499. X        fputs( buf, stdout );
  1500. X    }
  1501. X
  1502. X
  1503. X/* allocate_array - allocate memory for an integer array of the given size */
  1504. X
  1505. char *allocate_array( size, element_size )
  1506. int size, element_size;
  1507. X
  1508. X    {
  1509. X    register char *mem = malloc( (unsigned) (element_size * size) );
  1510. X
  1511. X    if ( mem == NULL )
  1512. X    flexfatal( "memory allocation failed in allocate_array()" );
  1513. X
  1514. X    return ( mem );
  1515. X    }
  1516. X
  1517. X
  1518. X/* bubble - bubble sort an integer array in increasing order
  1519. X *
  1520. X * synopsis
  1521. X *   int v[n], n;
  1522. X *   bubble( v, n );
  1523. X *
  1524. X * description
  1525. X *   sorts the first n elements of array v and replaces them in
  1526. X *   increasing order.
  1527. X *
  1528. X * passed
  1529. X *   v - the array to be sorted
  1530. X *   n - the number of elements of 'v' to be sorted */
  1531. X
  1532. bubble( v, n )
  1533. int v[], n;
  1534. X
  1535. X    {
  1536. X    register int i, j, k;
  1537. X
  1538. X    for ( i = n; i > 1; --i )
  1539. X    for ( j = 1; j < i; ++j )
  1540. X        if ( v[j] > v[j + 1] )    /* compare */
  1541. X        {
  1542. X        k = v[j];    /* exchange */
  1543. X        v[j] = v[j + 1];
  1544. X        v[j + 1] = k;
  1545. X        }
  1546. X    }
  1547. X
  1548. X
  1549. X/* clower - replace upper-case letter to lower-case
  1550. X *
  1551. X * synopsis:
  1552. X *    char clower(), c;
  1553. X *    c = clower( c );
  1554. X */
  1555. X
  1556. char clower( c )
  1557. register char c;
  1558. X
  1559. X    {
  1560. X    return ( isupper(c) ? tolower(c) : c );
  1561. X    }
  1562. X
  1563. X
  1564. X/* copy_string - returns a dynamically allocated copy of a string
  1565. X *
  1566. X * synopsis
  1567. X *    char *str, *copy, *copy_string();
  1568. X *    copy = copy_string( str );
  1569. X */
  1570. X
  1571. char *copy_string( str )
  1572. register char *str;
  1573. X
  1574. X    {
  1575. X    register char *c;
  1576. X    char *copy;
  1577. X
  1578. X    /* find length */
  1579. X    for ( c = str; *c; ++c )
  1580. X    ;
  1581. X
  1582. X    copy = malloc( (unsigned) ((c - str + 1) * sizeof( char )) );
  1583. X
  1584. X    if ( copy == NULL )
  1585. X    flexfatal( "dynamic memory failure in copy_string()" );
  1586. X
  1587. X    for ( c = copy; (*c++ = *str++); )
  1588. X    ;
  1589. X    
  1590. X    return ( copy );
  1591. X    }
  1592. X
  1593. X
  1594. X/* cshell - shell sort a character array in increasing order
  1595. X *
  1596. X * synopsis
  1597. X *
  1598. X *   char v[n];
  1599. X *   int n;
  1600. X *   cshell( v, n );
  1601. X *
  1602. X * description
  1603. X *   does a shell sort of the first n elements of array v.
  1604. X *
  1605. X * passed
  1606. X *   v - array to be sorted
  1607. X *   n - number of elements of v to be sorted
  1608. X */
  1609. cshell( v, n )
  1610. char v[];
  1611. int n;
  1612. X
  1613. X    {
  1614. X    int gap, i, j, jg;
  1615. X    char k;
  1616. X
  1617. X    for ( gap = n / 2; gap > 0; gap = gap / 2 )
  1618. X    for ( i = gap; i < n; ++i )
  1619. X        for ( j = i - gap; j >= 0; j = j - gap )
  1620. X        {
  1621. X        jg = j + gap;
  1622. X
  1623. X        if ( v[j] <= v[jg] )
  1624. X            break;
  1625. X
  1626. X        k = v[j];
  1627. X        v[j] = v[jg];
  1628. X        v[jg] = k;
  1629. X        }
  1630. X    }
  1631. X
  1632. X
  1633. X/* dataend - finish up a block of data declarations
  1634. X *
  1635. X * synopsis
  1636. X *    dataend();
  1637. X */
  1638. dataend()
  1639. X
  1640. X    {
  1641. X    if ( datapos > 0 )
  1642. X    dataflush();
  1643. X
  1644. X    /* add terminator for initialization */
  1645. X    puts( "    } ;\n" );
  1646. X
  1647. X    dataline = 0;
  1648. X    }
  1649. X
  1650. X
  1651. X
  1652. X/* dataflush - flush generated data statements
  1653. X *
  1654. X * synopsis
  1655. X *    dataflush();
  1656. X */
  1657. dataflush()
  1658. X
  1659. X    {
  1660. X    putchar( '\n' );
  1661. X
  1662. X    if ( ++dataline >= NUMDATALINES )
  1663. X    {
  1664. X    /* put out a blank line so that the table is grouped into
  1665. X     * large blocks that enable the user to find elements easily
  1666. X     */
  1667. X    putchar( '\n' );
  1668. X    dataline = 0;
  1669. X    }
  1670. X
  1671. X    /* reset the number of characters written on the current line */
  1672. X    datapos = 0;
  1673. X    }
  1674. X
  1675. X/* gettime - return current time
  1676. X *
  1677. X * synopsis
  1678. X *    char *gettime(), *time_str;
  1679. X *    time_str = gettime();
  1680. X */
  1681. X
  1682. X/* include sys/types.h to use time_t and make lint happy */
  1683. X
  1684. X#include <sys/types.h>
  1685. X
  1686. char *gettime()
  1687. X
  1688. X    {
  1689. X    time_t t, time();
  1690. X    char *result, *ctime(), *copy_string();
  1691. X
  1692. X    t = time( (long *) 0 );
  1693. X
  1694. X    result = copy_string( ctime( &t ) );
  1695. X
  1696. X    /* get rid of trailing newline */
  1697. X    result[24] = '\0';
  1698. X
  1699. X    return ( result );
  1700. X    }
  1701. X
  1702. X
  1703. X/* lerrif - report an error message formatted with one integer argument
  1704. X *
  1705. X * synopsis
  1706. X *    char msg[];
  1707. X *    int arg;
  1708. X *    lerrif( msg, arg );
  1709. X */
  1710. X
  1711. lerrif( msg, arg )
  1712. char msg[];
  1713. int arg;
  1714. X
  1715. X    {
  1716. X    char errmsg[MAXLINE];
  1717. X    (void) sprintf( errmsg, msg, arg );
  1718. X    flexerror( errmsg );
  1719. X    }
  1720. X
  1721. X
  1722. X/* lerrsf - report an error message formatted with one string argument
  1723. X *
  1724. X * synopsis
  1725. X *    char msg[], arg[];
  1726. X *    lerrsf( msg, arg );
  1727. X */
  1728. X
  1729. lerrsf( msg, arg )
  1730. char msg[], arg[];
  1731. X
  1732. X    {
  1733. X    char errmsg[MAXLINE];
  1734. X
  1735. X    (void) sprintf( errmsg, msg, arg );
  1736. X    flexerror( errmsg );
  1737. X    }
  1738. X
  1739. X
  1740. X/* flexerror - report an error message and terminate
  1741. X *
  1742. X * synopsis
  1743. X *    char msg[];
  1744. X *    flexerror( msg );
  1745. X */
  1746. X
  1747. flexerror( msg )
  1748. char msg[];
  1749. X
  1750. X    {
  1751. X    fprintf( stderr, "flex: %s\n", msg );
  1752. X    flexend( 1 );
  1753. X    }
  1754. X
  1755. X
  1756. X/* flexfatal - report a fatal error message and terminate
  1757. X *
  1758. X * synopsis
  1759. X *    char msg[];
  1760. X *    flexfatal( msg );
  1761. X */
  1762. X
  1763. flexfatal( msg )
  1764. char msg[];
  1765. X
  1766. X    {
  1767. X    fprintf( stderr, "flex: fatal internal error %s\n", msg );
  1768. X    flexend( 1 );
  1769. X    }
  1770. X
  1771. X
  1772. X/* line_directive_out - spit out a "# line" statement */
  1773. X
  1774. line_directive_out( output_file_name )
  1775. XFILE *output_file_name;
  1776. X
  1777. X    {
  1778. X    if ( infilename && gen_line_dirs ) 
  1779. X        fprintf( output_file_name, "# line %d \"%s\"\n", linenum, infilename );
  1780. X    }
  1781. X
  1782. X
  1783. X/* mk2data - generate a data statement for a two-dimensional array
  1784. X *
  1785. X * synopsis
  1786. X *    int value;
  1787. X *    mk2data( value );
  1788. X *
  1789. X *  generates a data statement initializing the current 2-D array to "value"
  1790. X */
  1791. mk2data( value )
  1792. int value;
  1793. X
  1794. X    {
  1795. X    if ( datapos >= NUMDATAITEMS )
  1796. X    {
  1797. X    putchar( ',' );
  1798. X    dataflush();
  1799. X    }
  1800. X
  1801. X    if ( datapos == 0 )
  1802. X    /* indent */
  1803. X    fputs( "    ", stdout );
  1804. X
  1805. X    else
  1806. X    putchar( ',' );
  1807. X
  1808. X    ++datapos;
  1809. X
  1810. X    printf( "%5d", value );
  1811. X    }
  1812. X
  1813. X
  1814. X/* mkdata - generate a data statement
  1815. X *
  1816. X * synopsis
  1817. X *    int value;
  1818. X *    mkdata( value );
  1819. X *
  1820. X *  generates a data statement initializing the current array element to
  1821. X *  "value"
  1822. X */
  1823. mkdata( value )
  1824. int value;
  1825. X
  1826. X    {
  1827. X    if ( datapos >= NUMDATAITEMS )
  1828. X    {
  1829. X    putchar( ',' );
  1830. X    dataflush();
  1831. X    }
  1832. X
  1833. X    if ( datapos == 0 )
  1834. X    /* indent */
  1835. X    fputs( "    ", stdout );
  1836. X
  1837. X    else
  1838. X    putchar( ',' );
  1839. X
  1840. X    ++datapos;
  1841. X
  1842. X    printf( "%5d", value );
  1843. X    }
  1844. X
  1845. X
  1846. X/* myctoi - return the integer represented by a string of digits
  1847. X *
  1848. X * synopsis
  1849. X *    char array[];
  1850. X *    int val, myctoi();
  1851. X *    val = myctoi( array );
  1852. X *
  1853. X */
  1854. X
  1855. int myctoi( array )
  1856. char array[];
  1857. X
  1858. X    {
  1859. X    int val = 0;
  1860. X
  1861. X    (void) sscanf( array, "%d", &val );
  1862. X
  1863. X    return ( val );
  1864. X    }
  1865. X
  1866. X
  1867. X/* myesc - return character corresponding to escape sequence
  1868. X *
  1869. X * synopsis
  1870. X *    char array[], c, myesc();
  1871. X *    c = myesc( array );
  1872. X *
  1873. X */
  1874. X
  1875. char myesc( array )
  1876. char array[];
  1877. X
  1878. X    {
  1879. X    switch ( array[1] )
  1880. X    {
  1881. X    case 'n': return ( '\n' );
  1882. X    case 't': return ( '\t' );
  1883. X    case 'f': return ( '\f' );
  1884. X    case 'r': return ( '\r' );
  1885. X    case 'b': return ( '\b' );
  1886. X
  1887. X    case '0':
  1888. X        if ( isdigit(array[2]) )
  1889. X        { /* \0<octal> */
  1890. X        char c, esc_char;
  1891. X        register int sptr = 2;
  1892. X
  1893. X        while ( isdigit(array[sptr]) )
  1894. X            /* don't increment inside loop control because the
  1895. X             * macro will expand it to two increments!  (Not a
  1896. X             * problem with the C version of the macro)
  1897. X             */
  1898. X            ++sptr;
  1899. X
  1900. X        c = array[sptr];
  1901. X        array[sptr] = '\0';
  1902. X
  1903. X        esc_char = otoi( array + 2 );
  1904. X        array[sptr] = c;
  1905. X
  1906. X        if ( esc_char == '\0' )
  1907. X            {
  1908. X            synerr( "escape sequence for null not allowed" );
  1909. X            return ( 1 );
  1910. X            }
  1911. X
  1912. X        return ( esc_char );
  1913. X        }
  1914. X
  1915. X        else
  1916. X        {
  1917. X        synerr( "escape sequence for null not allowed" );
  1918. X        return ( 1 );
  1919. X        }
  1920. X
  1921. X#ifdef NOTDEF
  1922. X    case '^':
  1923. X        {
  1924. X        register char next_char = array[2];
  1925. X
  1926. X        if ( next_char == '?' )
  1927. X        return ( 0x7f );
  1928. X        
  1929. X        else if ( next_char >= 'A' && next_char <= 'Z' )
  1930. X        return ( next_char - 'A' + 1 );
  1931. X    
  1932. X        else if ( next_char >= 'a' && next_char <= 'z' )
  1933. X        return ( next_char - 'z' + 1 );
  1934. X    
  1935. X        synerr( "illegal \\^ escape sequence" );
  1936. X
  1937. X        return ( 1 );
  1938. X        }
  1939. X#endif
  1940. X    }
  1941. X    
  1942. X    return ( array[1] );
  1943. X    }
  1944. X
  1945. X
  1946. X/* otoi - convert an octal digit string to an integer value
  1947. X *
  1948. X * synopsis:
  1949. X *    int val, otoi();
  1950. X *    char str[];
  1951. X *    val = otoi( str );
  1952. X */
  1953. X
  1954. int otoi( str )
  1955. char str[];
  1956. X
  1957. X    {
  1958. X#ifdef FTLSOURCE
  1959. X    fortran int gctoi()
  1960. X    int dummy = 1;
  1961. X
  1962. X    return ( gctoi( str, dummy, 8 ) );
  1963. X#else
  1964. X    int result;
  1965. X
  1966. X    (void) sscanf( str, "%o", &result );
  1967. X
  1968. X    return ( result );
  1969. X#endif
  1970. X    }
  1971. X
  1972. X
  1973. X
  1974. X
  1975. X/* reallocate_array - increase the size of a dynamic array */
  1976. X
  1977. char *reallocate_array( array, size, element_size )
  1978. char *array;
  1979. int size, element_size;
  1980. X
  1981. X    {
  1982. X    register char *new_array = realloc( array,
  1983. X                    (unsigned) (size * element_size ));
  1984. X
  1985. X    if ( new_array == NULL )
  1986. X    flexfatal( "attempt to increase array size failed" );
  1987. X    
  1988. X    return ( new_array );
  1989. X    }
  1990. X
  1991. X
  1992. X/* skelout - write out one section of the skeleton file
  1993. X *
  1994. X * synopsis
  1995. X *    skelout();
  1996. X *
  1997. X * DESCRIPTION
  1998. X *    Copies from skelfile to stdout until a line beginning with "%%" or
  1999. X *    EOF is found.
  2000. X */
  2001. skelout()
  2002. X
  2003. X    {
  2004. X    char buf[MAXLINE];
  2005. X
  2006. X    while ( fgets( buf, MAXLINE, skelfile ) != NULL )
  2007. X    if ( buf[0] == '%' && buf[1] == '%' )
  2008. X        break;
  2009. X    else
  2010. X        fputs( buf, stdout );
  2011. X    }
  2012. X
  2013. X
  2014. X/* transition_struct_out - output a yy_trans_info structure
  2015. X *
  2016. X * synopsis
  2017. X *     int element_v, element_n;
  2018. X *     transition_struct_out( element_v, element_n );
  2019. X *
  2020. X * outputs the yy_trans_info structure with the two elements, element_v and
  2021. X * element_n.  Formats the output with spaces and carriage returns.
  2022. X */
  2023. X
  2024. transition_struct_out( element_v, element_n )
  2025. int element_v, element_n;
  2026. X
  2027. X    {
  2028. X    printf( "%7d, %5d,", element_v, element_n );
  2029. X
  2030. X    datapos += TRANS_STRUCT_PRINT_LENGTH;
  2031. X
  2032. X    if ( datapos >= 75 )
  2033. X    {
  2034. X    printf( "\n" );
  2035. X
  2036. X    if ( ++dataline % 10 == 0 )
  2037. X        printf( "\n" );
  2038. X
  2039. X    datapos = 0;
  2040. X    }
  2041. X    }
  2042. END_OF_FILE
  2043. if test 9991 -ne `wc -c <'misc.c'`; then
  2044.     echo shar: \"'misc.c'\" unpacked with wrong size!
  2045. fi
  2046. # end of 'misc.c'
  2047. fi
  2048. if test -f 'scan.l' -a "${1}" != "-c" ; then 
  2049.   echo shar: Will not clobber existing file \"'scan.l'\"
  2050. else
  2051. echo shar: Extracting \"'scan.l'\" \(9189 characters\)
  2052. sed "s/^X//" >'scan.l' <<'END_OF_FILE'
  2053. X/* scan.l - scanner for flex input */
  2054. X
  2055. X/*
  2056. X * Copyright (c) 1987, the University of California
  2057. X * 
  2058. X * The United States Government has rights in this work pursuant to
  2059. X * contract no. DE-AC03-76SF00098 between the United States Department of
  2060. X * Energy and the University of California.
  2061. X * 
  2062. X * This program may be redistributed.  Enhancements and derivative works
  2063. X * may be created provided the new works, if made available to the general
  2064. X * public, are made available for use by anyone.
  2065. X */
  2066. X
  2067. X%{
  2068. X#include "flexdef.h"
  2069. X#include "parse.h"
  2070. X
  2071. X#define ACTION_ECHO fprintf( temp_action_file, "%s", yytext )
  2072. X#define MARK_END_OF_PROLOG fprintf( temp_action_file, "%%%% end of prolog\n" );
  2073. X
  2074. X#undef YY_DECL
  2075. X#define YY_DECL \
  2076. X    int flexscan()
  2077. X
  2078. X#define RETURNCHAR \
  2079. X    yylval = yytext[0]; \
  2080. X    return ( CHAR );
  2081. X
  2082. X#define RETURNNAME \
  2083. X    (void) strcpy( nmstr, yytext ); \
  2084. X    return ( NAME );
  2085. X
  2086. X#define PUT_BACK_STRING(str, start) \
  2087. X    for ( i = strlen( str ) - 1; i >= start; --i ) \
  2088. X        unput(str[i])
  2089. X%}
  2090. X
  2091. X%x SECT2 SECT2PROLOG SECT3 CODEBLOCK PICKUPDEF SC CARETISBOL NUM QUOTE
  2092. X%x FIRSTCCL CCL ACTION RECOVER BRACEERROR C_COMMENT C_COMMENT_2 ACTION_COMMENT
  2093. X%x ACTION_STRING PERCENT_BRACE_ACTION
  2094. X
  2095. WS        [ \t]+
  2096. X
  2097. OPTWS        [ \t]*
  2098. X
  2099. NAME        [a-z_][a-z_0-9]*
  2100. X
  2101. SCNAME        {NAME}
  2102. X
  2103. ESCSEQ        \\([^^\n]|"^".|0[0-9]{1,3})
  2104. X
  2105. X%%
  2106. X    static int bracelevel, didadef;
  2107. X    int i, cclval;
  2108. X    char nmdef[MAXLINE], myesc();
  2109. X
  2110. X^{WS}.*\n        ++linenum; ECHO; /* indented code */
  2111. X^#.*\n            ++linenum; ECHO; /* treat as a comment */
  2112. X^"/*"            ECHO; BEGIN(C_COMMENT);
  2113. X^"%s"(tart)?        return ( SCDECL );
  2114. X^"%x"            return ( XSCDECL );
  2115. X^"%{".*\n        ++linenum; line_directive_out( stdout ); BEGIN(CODEBLOCK);
  2116. X{WS}            return ( WHITESPACE );
  2117. X
  2118. X^"%%".*            {
  2119. X            sectnum = 2;
  2120. X            line_directive_out( stdout );
  2121. X            BEGIN(SECT2PROLOG);
  2122. X            return ( SECTEND );
  2123. X            }
  2124. X
  2125. X^"%"[^sx{%].*\n        {
  2126. X            fprintf( stderr,
  2127. X                 "old-style lex command at line %d ignored:\n\t%s",
  2128. X                 linenum, yytext );
  2129. X            ++linenum;
  2130. X            }
  2131. X
  2132. X^{NAME}            {
  2133. X            (void) strcpy( nmstr, yytext );
  2134. X            didadef = false;
  2135. X            BEGIN(PICKUPDEF);
  2136. X            }
  2137. X
  2138. X{SCNAME}        RETURNNAME;
  2139. X^{OPTWS}\n        ++linenum; /* allows blank lines in section 1 */
  2140. X\n            ++linenum; return ( '\n' );
  2141. X.            synerr( "illegal character" ); BEGIN(RECOVER);
  2142. X
  2143. X
  2144. X<C_COMMENT>"*/"        ECHO; BEGIN(0);
  2145. X<C_COMMENT>"*/".*\n    ++linenum; ECHO; BEGIN(0);
  2146. X<C_COMMENT>[^*\n]+    ECHO;
  2147. X<C_COMMENT>"*"        ECHO;
  2148. X<C_COMMENT>\n        ++linenum; ECHO;
  2149. X
  2150. X<CODEBLOCK>^"%}".*\n    ++linenum; BEGIN(0);
  2151. X<CODEBLOCK>.*\n        ++linenum; ECHO;
  2152. X
  2153. X<PICKUPDEF>{WS}        /* separates name and definition */
  2154. X
  2155. X<PICKUPDEF>[^ \t\n].*    {
  2156. X            (void) strcpy( nmdef, yytext );
  2157. X
  2158. X            for ( i = strlen( nmdef ) - 1;
  2159. X                  i >= 0 &&
  2160. X                  nmdef[i] == ' ' || nmdef[i] == '\t';
  2161. X                  --i )
  2162. X                ;
  2163. X
  2164. X            nmdef[i + 1] = '\0';
  2165. X
  2166. X                        ndinstal( nmstr, nmdef );
  2167. X            didadef = true;
  2168. X            }
  2169. X
  2170. X<PICKUPDEF>\n        {
  2171. X            if ( ! didadef )
  2172. X                synerr( "incomplete name definition" );
  2173. X            BEGIN(0);
  2174. X            ++linenum;
  2175. X            }
  2176. X
  2177. X<RECOVER>.*\n        ++linenum; BEGIN(0); RETURNNAME;
  2178. X
  2179. X
  2180. X<SECT2PROLOG>.*\n/[^ \t\n]    {
  2181. X            ++linenum;
  2182. X            ACTION_ECHO;
  2183. X            MARK_END_OF_PROLOG;
  2184. X            BEGIN(SECT2);
  2185. X            }
  2186. X
  2187. X<SECT2PROLOG>.*\n    ++linenum; ACTION_ECHO;
  2188. X
  2189. X<SECT2>^{OPTWS}\n    ++linenum; /* allow blank lines in section 2 */
  2190. X
  2191. X    /* this horrible mess of a rule matches indented lines which
  2192. X     * do not contain "/*".  We need to make the distinction because
  2193. X     * otherwise this rule will be taken instead of the rule which
  2194. X     * matches the beginning of comments like this one
  2195. X     */
  2196. X<SECT2>^{WS}([^/\n]|"/"[^*\n])*("/"?)\n    {
  2197. X            synerr( "indented code found outside of action" );
  2198. X            ++linenum;
  2199. X            }
  2200. X
  2201. X<SECT2>"<"        BEGIN(SC); return ( '<' );
  2202. X<SECT2>^"^"        return ( '^' );
  2203. X<SECT2>\"        BEGIN(QUOTE); return ( '"' );
  2204. X<SECT2>"{"/[0-9]        BEGIN(NUM); return ( '{' );
  2205. X<SECT2>"{"[^0-9\n][^}\n]*    BEGIN(BRACEERROR);
  2206. X<SECT2>"$"/[ \t\n]    return ( '$' );
  2207. X
  2208. X<SECT2>{WS}"%{"        {
  2209. X            bracelevel = 1;
  2210. X            BEGIN(PERCENT_BRACE_ACTION);
  2211. X            return ( '\n' );
  2212. X            }
  2213. X<SECT2>{WS}"|".*\n    ++linenum; return ( '\n' );
  2214. X
  2215. X<SECT2>^{OPTWS}"/*"    ACTION_ECHO; BEGIN(C_COMMENT_2);
  2216. X
  2217. X<SECT2>{WS}        { /* needs to be separate from following rule due to
  2218. X               * bug with trailing context
  2219. X               */
  2220. X            bracelevel = 0;
  2221. X            BEGIN(ACTION);
  2222. X            return ( '\n' );
  2223. X            }
  2224. X
  2225. X<SECT2>{OPTWS}/\n    {
  2226. X            bracelevel = 0;
  2227. X            BEGIN(ACTION);
  2228. X            return ( '\n' );
  2229. X            }
  2230. X
  2231. X<SECT2>^{OPTWS}\n    ++linenum; return ( '\n' );
  2232. X
  2233. X<SECT2>^"%%".*        {
  2234. X            /* guarantee that the SECT3 rule will have something
  2235. X             * to match
  2236. X             */
  2237. X            yyless(1);
  2238. X            sectnum = 3;
  2239. X            BEGIN(SECT3);
  2240. X            return ( EOF ); /* to stop the parser */
  2241. X            }
  2242. X
  2243. X<SECT2>"["([^\\\]\n]|{ESCSEQ})+"]"    {
  2244. X            (void) strcpy( nmstr, yytext );
  2245. X
  2246. X            /* check to see if we've already encountered this ccl */
  2247. X            if ( (cclval = ccllookup( nmstr )) )
  2248. X                {
  2249. X                yylval = cclval;
  2250. X                ++cclreuse;
  2251. X                return ( PREVCCL );
  2252. X                }
  2253. X            else
  2254. X                {
  2255. X                /* we fudge a bit.  We know that this ccl will
  2256. X                 * soon be numbered as lastccl + 1 by cclinit
  2257. X                 */
  2258. X                cclinstal( nmstr, lastccl + 1 );
  2259. X
  2260. X                /* push back everything but the leading bracket
  2261. X                 * so the ccl can be rescanned
  2262. X                 */
  2263. X                PUT_BACK_STRING(nmstr, 1);
  2264. X
  2265. X                BEGIN(FIRSTCCL);
  2266. X                return ( '[' );
  2267. X                }
  2268. X            }
  2269. X
  2270. X<SECT2>"{"{NAME}"}"    {
  2271. X            register char *nmdefptr;
  2272. X            char *ndlookup();
  2273. X
  2274. X            (void) strcpy( nmstr, yytext );
  2275. X            nmstr[yyleng - 1] = '\0';  /* chop trailing brace */
  2276. X
  2277. X            /* lookup from "nmstr + 1" to chop leading brace */
  2278. X            if ( ! (nmdefptr = ndlookup( nmstr + 1 )) )
  2279. X                synerr( "undefined {name}" );
  2280. X
  2281. X            else
  2282. X                { /* push back name surrounded by ()'s */
  2283. X                unput(')');
  2284. X                PUT_BACK_STRING(nmdefptr, 0);
  2285. X                unput('(');
  2286. X                }
  2287. X            }
  2288. X
  2289. X<SECT2>[/|*+?.()]    return ( yytext[0] );
  2290. X<SECT2>.        RETURNCHAR;
  2291. X<SECT2>\n        ++linenum; return ( '\n' );
  2292. X
  2293. X
  2294. X<SC>","            return ( ',' );
  2295. X<SC>">"            BEGIN(SECT2); return ( '>' );
  2296. X<SC>">"/"^"        BEGIN(CARETISBOL); return ( '>' );
  2297. X<SC>{SCNAME}        RETURNNAME;
  2298. X<SC>.            synerr( "bad start condition name" );
  2299. X
  2300. X<CARETISBOL>"^"        BEGIN(SECT2); return ( '^' );
  2301. X
  2302. X
  2303. X<QUOTE>[^"\n]        RETURNCHAR;
  2304. X<QUOTE>\"        BEGIN(SECT2); return ( '"' );
  2305. X
  2306. X<QUOTE>\n        {
  2307. X            synerr( "missing quote" );
  2308. X            BEGIN(SECT2);
  2309. X            ++linenum;
  2310. X            return ( '"' );
  2311. X            }
  2312. X
  2313. X
  2314. X<FIRSTCCL>"^"/[^-\n]    BEGIN(CCL); return ( '^' );
  2315. X<FIRSTCCL>"^"/-        return ( '^' );
  2316. X<FIRSTCCL>-        BEGIN(CCL); yylval = '-'; return ( CHAR );
  2317. X<FIRSTCCL>.        BEGIN(CCL); RETURNCHAR;
  2318. X
  2319. X<CCL>-/[^\]\n]        return ( '-' );
  2320. X<CCL>[^\]\n]        RETURNCHAR;
  2321. X<CCL>"]"            BEGIN(SECT2); return ( ']' );
  2322. X
  2323. X
  2324. X<NUM>[0-9]+        {
  2325. X            yylval = myctoi( yytext );
  2326. X            return ( NUMBER );
  2327. X            }
  2328. X
  2329. X<NUM>","            return ( ',' );
  2330. X<NUM>"}"            BEGIN(SECT2); return ( '}' );
  2331. X
  2332. X<NUM>.            {
  2333. X            synerr( "bad character inside {}'s" );
  2334. X            BEGIN(SECT2);
  2335. X            return ( '}' );
  2336. X            }
  2337. X
  2338. X<NUM>\n            {
  2339. X            synerr( "missing }" );
  2340. X            BEGIN(SECT2);
  2341. X            ++linenum;
  2342. X            return ( '}' );
  2343. X            }
  2344. X
  2345. X
  2346. X<BRACEERROR>"}"        synerr( "bad name in {}'s" ); BEGIN(SECT2);
  2347. X<BRACEERROR>\n        synerr( "missing }" ); ++linenum; BEGIN(SECT2);
  2348. X
  2349. X
  2350. X<PERCENT_BRACE_ACTION>{OPTWS}"%}".*    bracelevel = 0;
  2351. X<PERCENT_BRACE_ACTION>.*        ACTION_ECHO;
  2352. X<PERCENT_BRACE_ACTION>\n        {
  2353. X            ++linenum;
  2354. X            ACTION_ECHO;
  2355. X            if ( bracelevel == 0 )
  2356. X                {
  2357. X                fputs( "\tYY_BREAK\n", temp_action_file );
  2358. X                BEGIN(SECT2);
  2359. X                }
  2360. X            }
  2361. X
  2362. X<ACTION>"{"        ACTION_ECHO; ++bracelevel;
  2363. X<ACTION>"}"        ACTION_ECHO; --bracelevel;
  2364. X<ACTION>[^{}"'/\n]+    ACTION_ECHO;
  2365. X<ACTION>"/*"        ACTION_ECHO; BEGIN(ACTION_COMMENT);
  2366. X<ACTION>"'"([^'\\\n]|\\.)*"'"    ACTION_ECHO; /* character constant */
  2367. X<ACTION>\"        ACTION_ECHO; BEGIN(ACTION_STRING);
  2368. X<ACTION>\n        {
  2369. X            ++linenum;
  2370. X            ACTION_ECHO;
  2371. X            if ( bracelevel == 0 )
  2372. X                {
  2373. X                fputs( "\tYY_BREAK\n", temp_action_file );
  2374. X                BEGIN(SECT2);
  2375. X                }
  2376. X            }
  2377. X<ACTION>.        ACTION_ECHO;
  2378. X
  2379. X<ACTION_COMMENT>"*/"    ACTION_ECHO; BEGIN(ACTION);
  2380. X<ACTION_COMMENT>[^*\n]+    ACTION_ECHO;
  2381. X<ACTION_COMMENT>"*"    ACTION_ECHO;
  2382. X<ACTION_COMMENT>\n    ++linenum; ACTION_ECHO;
  2383. X<ACTION_COMMENT>.    ACTION_ECHO;
  2384. X
  2385. X<C_COMMENT_2>"*/"    ACTION_ECHO; BEGIN(SECT2);
  2386. X<C_COMMENT_2>"*/".*\n    ++linenum; ACTION_ECHO; BEGIN(SECT2);
  2387. X<C_COMMENT_2>[^*\n]+    ACTION_ECHO;
  2388. X<C_COMMENT_2>"*"    ACTION_ECHO;
  2389. X<C_COMMENT_2>\n        ++linenum; ACTION_ECHO;
  2390. X
  2391. X<ACTION_STRING>[^"\\\n]+    ACTION_ECHO;
  2392. X<ACTION_STRING>\\.    ACTION_ECHO;
  2393. X<ACTION_STRING>\n    ++linenum; ACTION_ECHO;
  2394. X<ACTION_STRING>\"    ACTION_ECHO; BEGIN(ACTION);
  2395. X<ACTION_STRING>.    ACTION_ECHO;
  2396. X
  2397. X
  2398. X<SECT2,QUOTE,CCL>{ESCSEQ}    {
  2399. X            yylval = myesc( yytext );
  2400. X            return ( CHAR );
  2401. X            }
  2402. X
  2403. X<FIRSTCCL>{ESCSEQ}    {
  2404. X            yylval = myesc( yytext );
  2405. X            BEGIN(CCL);
  2406. X            return ( CHAR );
  2407. X            }
  2408. X
  2409. X
  2410. X<SECT3>.|\n        {
  2411. X            register int numchars;
  2412. X
  2413. X            /* black magic - we know the names of a flex scanner's
  2414. X             * internal variables.  We cap the input buffer with
  2415. X             * an end-of-string and dump it to the output.
  2416. X             */
  2417. X            YY_DO_BEFORE_SCAN; /* recover from setting up yytext */
  2418. X
  2419. X#ifdef FLEX_FAST_SKEL
  2420. X            fputs( yy_c_buf_p + 1, stdout );
  2421. X#else
  2422. X            yy_ch_buf[yy_e_buf_p + 1] = '\0';
  2423. X
  2424. X            /* ignore the first character; it's the second '%'
  2425. X             * put back by the yyless(1) above
  2426. X             */
  2427. X            fputs( yy_ch_buf + yy_c_buf_p + 1, stdout );
  2428. X#endif
  2429. X
  2430. X            /* if we don't do this, the data written by write()
  2431. X             * can get overwritten when stdout is finally flushed
  2432. X             */
  2433. X            (void) fflush( stdout );
  2434. X
  2435. X            while ( (numchars = read( fileno(yyin), yy_ch_buf,
  2436. X                          YY_BUF_MAX )) > 0 )
  2437. X                (void) write( fileno(stdout), yy_ch_buf, numchars );
  2438. X    
  2439. X            if ( numchars < 0 )
  2440. X                flexerror( "fatal read error in section 3" );
  2441. X
  2442. X            return ( EOF );
  2443. X            }
  2444. X%%
  2445. END_OF_FILE
  2446. if test 9189 -ne `wc -c <'scan.l'`; then
  2447.     echo shar: \"'scan.l'\" unpacked with wrong size!
  2448. fi
  2449. # end of 'scan.l'
  2450. fi
  2451. echo shar: End of archive 2 \(of 5\).
  2452. cp /dev/null ark2isdone
  2453. MISSING=""
  2454. for I in 1 2 3 4 5 ; do
  2455.     if test ! -f ark${I}isdone ; then
  2456.     MISSING="${MISSING} ${I}"
  2457.     fi
  2458. done
  2459. if test "${MISSING}" = "" ; then
  2460.     echo You have unpacked all 5 archives.
  2461.     rm -f ark[1-9]isdone
  2462. else
  2463.     echo You still need to unpack the following archives:
  2464.     echo "        " ${MISSING}
  2465. fi
  2466. ##  End of shell archive.
  2467. exit 0
  2468.